﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DAL;
using System.Data;


namespace BLL
{
   public class ClsDangNhapBus
    {
       public ClsDangNhapInfo Info = new ClsDangNhapInfo();
       public bool Login()
       {
           ClsDataAccess oConnection = new ClsDataAccess();
           string strSql = @"SELECT * FROM NguoiDung  WHERE  NguoiDung.UserName like'" + Info.UserName + "' AND PassWord like '" + Info.PassWord  + "' AND Quyen like '" + Info.Quyen + "'";

           if (oConnection.ExecuteSelect(strSql))
           {
               if (oConnection.ODataTable.Rows.Count > 0)
               {
                   return true;
               }
               else
               {
                   return false;
               }
           }
           else
           {
               return false;
           }


       }
       public bool ChangePass()
       {
           string strSql = @"UPDATE NguoiDung SET PassWord ='" + Info.NewPassWord + "' WHERE  NguoiDung.UserName like'" + Info.UserName + "' AND PassWord like '" + Info.PassWord  +  "'";
           ClsDataAccess oConnection = new ClsDataAccess();

           if (oConnection.ExecuteNonQuery(strSql) >0)
           {
               return true;
           }
           else
           {
               return false;
           }
       }
       public bool Them()
       {
           string strSql = @"INSERT INTO NguoiDung VALUES('" + Info.UserName + "','" + Info.PassWord + "','" + Info.Quyen + "')";
           ClsDataAccess oConnection = new ClsDataAccess();
           return (oConnection.ExecuteStoredProcedure(strSql));
       }
    }
}
